package com.ruicar.afs.cloud.common.mq.rabbit.config;

import com.ruicar.afs.cloud.common.mq.rabbit.component.TransCodeMapComponent;
import com.ruicar.afs.cloud.common.mq.rabbit.init.RabbitMqInit;
import com.ruicar.afs.cloud.common.mq.rabbit.register.AfsRabbitMqSenderRegister;
import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import javax.annotation.PostConstruct;


/**
 * The type RabbitMqConfiguration
 * <p>Description: </p>
 *
 * @author Fzero
 * @version 1.0
 * @date Created on 2020.06.11 16:09:10
 * @since 1.0
 */
@Configuration
@ConditionalOnProperty(prefix = "com.ruicar.afs.cloud.mq.rabbit", name = "enable")
@EnableConfigurationProperties(value = AfsRabbitMqProperties.class)
@AllArgsConstructor
@Import({RabbitBootstrapConfiguration.class, AfsRabbitMqSenderRegister.class})
public class RabbitMqConfiguration {
    private ApplicationContext applicationContext;
    private AfsRabbitMqProperties afsRabbitMqProperties;

    @Bean
    public TransCodeMapComponent transCodeMapComponent() {
        return new TransCodeMapComponent();
    }

    @PostConstruct
    public void init() throws Exception {
        new RabbitMqInit(afsRabbitMqProperties, applicationContext);
    }
}
